-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add to_python(..., serialize_generators=False) #1401
Conversation
618a1d4
to
fd0e67b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1401 +/- ##
==========================================
- Coverage 90.21% 89.54% -0.67%
==========================================
Files 106 109 +3
Lines 16339 17387 +1048
Branches 36 41 +5
==========================================
+ Hits 14740 15569 +829
- Misses 1592 1798 +206
- Partials 7 20 +13
... and 40 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #1401 will not alter performanceComparing Summary
|
fd0e67b
to
5210b1d
Compare
This disables wrapping/consuming generators while serializing, while calling the fallback function on them. In many cases, we want to implement some custom serialization logic for generators (such as io.IOBase), instead of consuming them whole.
5210b1d
to
d073938
Compare
Huh, thanks for the PR! Not sure if we want to add this runtime setting. Let me circle back with the team + will get back to you later this week. |
I think something like pydantic/pydantic#10728 solves this use case with a more general solution. |
This disables wrapping/consuming generators while serializing, while calling the fallback function on them.
In many cases, we want to implement some custom serialization logic for generators (such as io.IOBase), instead of consuming them whole.
Change Summary
Add
serialize_generators
parameter toto_python
,to_json
, etc. This changes the serialization to handle generators as if they were 'unknown' types. By default, this callsfallback
or leaves them alone into_python
, and callsfallback
into_json
or errors there.Related issue number
pydantic-core part of a fix for pydantic/pydantic#8907 . If this change gets merged, we'll submit another PR to
pydantic
to havemodel_dump
forward aserialize_generators
argument.Checklist
pydantic-core
(except for expected changes)